package com.kayden.book.service;

import com.kayden.book.dao.BookDao;
import com.kayden.book.enums.BookStatusEnum;
import com.kayden.book.mapper.BookMapper;
import com.kayden.book.model.BookInfo;
import com.kayden.book.model.PageRequest;
import com.kayden.book.model.ResponseResult;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BookService {



    @Autowired
    public BookMapper bookMapper;


//    public List<BookInfo> getList(){
//        List<BookInfo> bookInfos = bookDao.mockData();
//
//        for (BookInfo bookInfo : bookInfos) {
//            if (bookInfo.getStatus() == 1){
//                bookInfo.setStatusCN("可借阅");
//            }else{
//                bookInfo.setStatusCN("不可借阅");
//            }
//        }
//        return bookInfos;
//    }

    public ResponseResult<BookInfo> getListByPage(PageRequest pageRequest){
        Integer count = bookMapper.count();
        List<BookInfo> bookInfos = bookMapper.selectBooksByPage(pageRequest);
        for(BookInfo bookInfo : bookInfos){
            bookInfo.setStatusCN(BookStatusEnum.getStatusByCode(bookInfo.getStatus()).getDesc());
        }
        return new ResponseResult<>(count,bookInfos,pageRequest);
    }

    public void addBook(BookInfo bookInfo){
        bookMapper.addBook(bookInfo);
    }

    public BookInfo queryBookByInd(Integer bookId){
        return bookMapper.queryBookInfoById(bookId);
    }

    public  void updateBook(BookInfo bookInfo){
        bookMapper.updateBook(bookInfo);
    }

    public Integer batchDelete(List<Integer> ids){
        return bookMapper.batchDelete(ids);
    }

}
